﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.ETL.Domain
{
    public interface IDtSerManager
    {
        /// <summary>
        /// 创建数据服务
        /// </summary>
        /// <returns></returns>
        ServiceResult<Entities.DtSer> CreateDataService(EtlDbContext dbContext, string userId, Guid folderId, string name, string address, bool needAuth,
            string authUser,
            string authPassword,
            Guid categoryId,
            Guid typeId,
            string description);

        /// <summary>
        /// 创建数据源
        /// </summary>
        /// <returns></returns>
        ServiceResult CreateDataSource(EtlDbContext dbContext, string userId, Guid dtSerId, string name, string value, int type, string parameterSettings, string columnSettings,
            string settings);

        bool CanCreateDataSource();

        /// <summary>
        /// 
        /// 枚举数据源
        /// </summary>
        /// <param name="address"></param>
        /// <param name="needAuth"></param>
        /// <param name="authUser"></param>
        /// <param name="authPassword"></param>
        /// <returns></returns>
        List<string> EnumerateDataSource(string address, bool needAuth, string authUser, string authPassword);
    }

    public static class DtSerManagerFactory
    {
        public static IDtSerManager Create(string assemblyName, string typeName)
        {
            try
            {
                Assembly assembly = Assembly.Load(assemblyName);
                Type type = assembly.GetType(typeName);

                return (IDtSerManager)assembly.CreateInstance(typeName);
            }
            catch(Exception ex)
            {
                return null;
            }
        }
    }
}
